//
//  TouchView.m
//  UI29__Block
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "TouchView.h"


@interface TouchView ()
@property (strong, nonatomic) IBOutlet UIView *view;
@property (nonatomic, copy)void (^block)(TouchView *);

@property (nonatomic, copy)void (^deleBtnHandle)(UIButton *);
@property (nonatomic, copy)void (^editBtnHandle)(UIButton *);
@end


@implementation TouchView


- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    
    self = [super initWithCoder:aDecoder];
    if (self) {
        
        [[NSBundle mainBundle]loadNibNamed:@"TouchView" owner:self options:nil];
        self.view.frame = self.bounds;
        [self addSubview:self.view];
        
    }
    return self;
}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    // 点击之后, 调用 blcok
    
    self.block(self);
    
}


// 实现带 block 参数的方法
- (void)viewDidClick:(void (^)(TouchView *))block {
    
    
    self.block = block;
    
    
}


- (void)buttonHandle:(void (^) (UIButton *deleBtn))block{
    
    self.deleBtnHandle = block;
    
}






/** 点击删除 button */
- (IBAction)handleButtonAction:(id)sender {
    
    self.deleBtnHandle((UIButton *)sender);
    
    
    
}


- (void)editBtnHandle:(void(^)(UIButton *editBun))block1 deleBtnHandle:(void(^)(UIButton *deleBtn))block2 {
    
    self.editBtnHandle = block1;
    self.deleBtnHandle = block2;
    
    
    
    
}

- (IBAction)handleEdit:(id)sender {
    
    self.editBtnHandle((UIButton *)sender);
    
    
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
